package com.shycloud.mido.member.constants;

import com.shycloud.mido.common.util.consistenthash.ConsistentHash;
import com.shycloud.mido.common.util.consistenthash.HashFunction;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Xiaoxing Yu
 * @date 2020/9/17
 **/

@Component
public class ShoppingStockConstants {

	public static ConsistentHash<Integer> ipHash = null;

	public final static String ORDER_TYPE_ADMIN = "3";

	public final static String ONLINE_COURSE_CHINESE = "在线课";

	public final static String MASTER_CHINESE = "纠错大师";

	public final static String ONE_YES = "1";
	public final static String ZERO_NO = "0";

	public final static String ZERO_STRING = "0";
	public final static String ONE_STRING = "1";
	public final static String TWO_STRING = "2";
	public final static String THREE_STRING = "3";
	public final static String FOUR_STRING = "4";
	public final static String FIVE_STRING = "5";

	public final static Integer ONE = 1;
	public final static Integer TWO = 2;
	public final static Integer THREE = 3;
	public final static Integer FOUR = 4;
	public final static Integer FIVE = 5;

	public final static String ORDER_UNCOMMITED = "0";
	public final static String ORDER_COMMITED = "1";

	public final static String STATUS_NOT_OUT = "0";
	public final static String STATUS_OUT = "1";

	public final static String DEVICE_UNLIMITED = "0";
	public final static String DEVICE_RENT = "1";

	public final static Integer MASTER_PRODUCT_ID = 2;

	public final static String PAY_TYPE_ALIPAY = "1";
	public final static String PAY_TYPE_WECHAT = "2";

	public final static String SUCCESS = "SUCCESS";
	public final static String FAIL = "FAIL";

	public final static Integer ONLINE_COURSE_PRODUCT_ID = 4;

	public final static Integer HEADQUARTER_OPT_ID = 999999;

	@PostConstruct
	public void init() {
		Set<Integer> nodes = new HashSet<Integer>();
		for (int i = 0; i < 100; i++) {
			nodes.add(i);
		}

		ipHash = new ConsistentHash<Integer>(new HashFunction(), 50, nodes);
	}

	static {
		Set<Integer> nodes = new HashSet<Integer>();
		for (int i = 0; i < 100; i++) {
			nodes.add(i);
		}

		ipHash = new ConsistentHash<Integer>(new HashFunction(), 50, nodes);
	}

	public static Integer getConsistentHash(Object key) {
		return ipHash.get(key);
	}

//	public static void main(String[] args) {
//		List<String> ipList = new ArrayList();
//		ipList.add("192.168.1.165");
//		ipList.add("192.168.1.86");
//		ipList.add("192.168.1.34");
//		ipList.add("192.168.1.5");
//		ipList.add("192.168.1.211");
//		ipList.add("192.168.1.28");
//		ipList.add("192.168.1.250");
//		ipList.add("192.168.1.229");
//		ipList.add("192.168.1.166");
//		for (String s: ipList) {
//			System.out.println(MemberConstants.getConsistentHash(s));
//		}
//	}

}
